package com.aggron.concurrency.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author LR2SD
 * @description Future测试类
 * @date 2018-06-14 19:11
 */
@Slf4j
public class FutureTaskExample {

     static class MyCallable implements Callable<String>{

         @Override
         public String call() throws Exception {
             log.info("do something");
             Thread.sleep(5000);
             return "done";
         }
     }

     public static void main(String [] args)throws Exception{
         FutureTask<String> futureTask=new FutureTask<>(new MyCallable());
         new Thread(futureTask).start();
         log.info("do something in main");
         String result=futureTask.get();
         log.info("result:{}",result);
     }
}
